package com.xaaef.jvm;

/**
 * <p>
 * 虚拟机会保证 <<clinit>> 方法 在多线程下被同步加锁！
 * </p>
 *
 * @author Wang Chen Chen<932560435@qq.com>
 * @date 2022/2/15 21:39
 */

public class DeadThreadTest {

    public static void main(String[] args) {
        Runnable r = () -> {
            System.out.printf("%s 开始....%n", Thread.currentThread().getName());
            new DeadThread();
            System.out.printf("%s 结束....%n", Thread.currentThread().getName());
        };

        Thread t1 = new Thread(r, "线程1");
        Thread t2 = new Thread(r, "线程2");
        t1.start();
        t2.start();
    }


}


class DeadThread {

    static {
        if (true) {
            System.out.printf("%s 正在执行 DeadThread 的初始化....%n", Thread.currentThread().getName());
            while (true) {
            }
        }
    }

}

